package com.zwq.common.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;


@Data
@Schema(name = "响应封装类")
public class ResponseResult<T> implements Serializable {

    @Schema(name = "响应状态码")
    private ResponseCode code;

    @Schema(name = "响应信息")
    private String message;

    @Schema(name = "响应数据")
    private T data;

    @Schema(name = "响应是否成功")
    private boolean success;

    public static <T> ResponseResult<T> success(T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(ResponseCode.SUCCESS);
        responseResult.setData(data);
        responseResult.setSuccess(true);
        return responseResult;
    }

    public static <T> ResponseResult<T> error(Exception exception) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(ResponseCode.ERROR);
        responseResult.setSuccess(false);
        responseResult.setMessage(exception.getMessage());
        return responseResult;
    }


}
